﻿using Koala.Pro.Common;
using Koala.Pro.Core;
using Koala.Pro.Core.Dto;
using Koala.Pro.Models;
using SqlSugar;
using System.Data;
using System.Linq.Expressions;

namespace Koala.Pro.Services
{
    public interface IMyCrudService<TEntity, TKey, TGetListInput> where TEntity : class, IEntity<TKey>, new() where TGetListInput : IPagedAndSortedResultRequest
    {
        IApiUserSession CurrentApiUser { get; set; }

        void SetDbConfigName(string dbConfigName);

        Task<ListResultDto<TEntity>> GetAllAsync();

        Task<ListResultDto<TEntity>> GetAllAsync(Expression<Func<TEntity, bool>> input, string orderBy = null);

        Task<ListResultDto<TEntity>> GetAllByIdsAsync(IEnumerable<TKey> input);

        Task<PagedResultDto<TEntity>> GetListAsync(TGetListInput input);

        Task<PagedResultDto<TEntity>> GetListByFilterAsync(PagedSortedAndFilteredInputDto input);

        Task<long> CountAsync(TGetListInput input);

        Task<long> CountAsync(Expression<Func<TEntity, bool>> input);

        Task<TEntity> GetAsync(TKey id);

        Task<TEntity> GetFirstAsync(Expression<Func<TEntity, bool>> input, string orderBy = null);

        Task<bool> DeleteAsync(TEntity input);

        Task<bool> DeleteAsync(Expression<Func<TEntity, bool>> input);

        Task<bool> DeleteAsync(TKey id);

        Task<bool> DeleteAsync(IEnumerable<TKey> input);

        Task<bool> DeleteByConditionAsync(string strWhere);

        Task<bool> DeleteByConditionAsync(string strWhere, List<SugarParameter> parameters);

        Task<bool> InsertAsync(TEntity input);

        Task<int> InsertReturnIdentityAsync(TEntity input);

        Task<long> InsertReturnBigIdentityAsync(TEntity input);

        Task<bool> InsertRangeAsync(List<TEntity> input);

        Task<bool> UpdateAsync(TEntity input);

        Task<bool> UpdateRangeAsync(List<TEntity> input);

        Task<bool> InsertOrUpdateAsync(TEntity input, TKey id);

        Task<bool> IsExistAsync(TKey id);

        Task<bool> IsExistAsync(Expression<Func<TEntity, bool>> input);

        Task<Dictionary<string, string>> GetColumnNameAlias();

        Task<string> GetDisplayColumns();

        Task<List<string>> GetFieldList(Expression<Func<TEntity, object>> selector, Expression<Func<TEntity, bool>> where = null);

        ListResultDto<TEntity> SqlQuery(string sql, List<SugarParameter> parameters = null);

        string SqlValueList(string sql, List<SugarParameter> parameters = null);

        int SqlExecute(string sql, List<SugarParameter> parameters = null);

        Task<int> SqlExecuteAync(string sql, List<SugarParameter> parameters = null);

        Task<int> StoreProcExecuteAsync(string storeProcName, List<SugarParameter> parameters = null);

        int StoreProcExecute(string storeProcName, List<SugarParameter> parameters = null);

        DataTable SqlTable(string sql, List<SugarParameter> parameters = null);

        DataSet SqlDataSet(string sql, List<SugarParameter> parameters = null);

        void BeginTran();

        void CommitTran();

        void RollbackTran();

        Task AddOperationLog(string logType, string note);
    }
}
